<%--
  Created by IntelliJ IDEA.
  User: leixiaolong
  Date: 2018/12/6
  Time: 9:51 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>角色授权</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/layui/css/layui.css" media="all"
          type="text/css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/extend/dtree/font/iconfont.css" media="all"
          type="text/css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/extend/dtree/dtree.css" media="all"
          type="text/css">
</head>
<body>
    <div style="height: 550px;overflow: auto;" id="toolbarDiv">
        <ul id="demoTree" class="dtree" data-id="0"></ul>
    </div>
</body>
</html>

<script language='javascript' src="${pageContext.request.contextPath}/plugins/layui/layui.js"></script>

<script>
    function init(data){
        layui.config({
            base: '/plugins/extend/dtree/',
        }).use(["dtree", "form", "jquery"], function () {
            var dtree = layui.dtree, $ = layui.jquery;

            // 渲染，使用data渲染
            dtreeIns = dtree.render({
                elem: "#demoTree",
                // data: dtreedata,
                url: "loadMenuTree?roleId="+data,
                initLevel: "1",
                async: false,
                toolbar: true,
                toolbarScroll: "#demoTree", //划重点，必须配置，属性含义请参考文档
                // toolbarLoad: "node",  // 表示工具栏加载的节点，  可选的值还有：noleaf（非最后一级）,leaf（最后一级节点）
                // toolbarStyle: {
                //     title: "菜单"
                // },
                checkbar: true,
                checkbarData: "choose",
                checkbarType: "all" // 默认就是all，其他的值为： no-all   p-casc   self
            });

            // 点击节点触发回调
            dtree.on("node('demoTree')", function (param) {
                debugger
                var params = dtree.getCheckbarNodesParam("demoTree");

                console.log(params);
                // debugger
                // var node = dtreeIns.getNowNode();
                // if(param.ischecked == '0'){
                //     dtreeIns.checkStatus(node).check();
                // }
                //
                //
                // dtreeIns.changeCheck();

                // dtreeIns.changeTreeNodeEdit(true);

                // layer.msg(JSON.stringify(param));

                // dtree.reload('demoTree', {
                //     iframe: {
                //         iframeElem: "#iframe_content",  // iframe的ID
                //         iframeUrl: "menu_content", // iframe路由到的地址
                //         iframeLoad: "all",
                //         iframeRequest: param
                //     }
                // });

            });
        });
    }


    function getChoosed(){
        var params;
        layui.config({
            base: '/plugins/extend/dtree/',
        }).use(["dtree", "jquery"], function () {
            var dtree = layui.dtree;
            params = dtree.getCheckbarNodesParam("demoTree");
        });
        return params;
    }

</script>
